package com.cc.jdkjucdemo.CompletableFuture;

import java.util.concurrent.*;

public class CompletableFutureDemo02_01 {

    static ThreadPoolExecutor executor = new ThreadPoolExecutor(
            5,
            50,
            10,
            TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(100),
            Executors.defaultThreadFactory(),
            new ThreadPoolExecutor.AbortPolicy());

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("主线程start ......");
        // 没有返回结果，可以执行任务
        CompletableFuture<Void> whenCompleteAsync1 = CompletableFuture.runAsync(() -> {
            System.out.println("子线程执行了：" + Thread.currentThread().getName());
            int i = 10 / 0;
        }, executor).handle((res, ex) -> {
            if (ex != null) {
                System.out.println("异常：" + ex);
            }
            return res;
        });

        System.out.println("主线程end ......");
        executor.shutdown();
    }
}
